﻿using Outdoors.Helpers.Constants;
using Outdoors.Helpers.Foursquare;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Outdoors.ViewModels
{
    public class ActivityViewModel : INotifyPropertyChanged
    {
        private double Latitude { get; set; }
        private double Longitude { get; set; }
        public ObservableCollection<ActivityItemViewModel> Items { get; private set; }
        public ActivityViewModel()
        {
            this.Items = new ObservableCollection<ActivityItemViewModel>();
        }
        public ActivityViewModel(double Latitude, double Longitude)
        {
            this.Items = new ObservableCollection<ActivityItemViewModel>();
            this.Latitude = Latitude;
            this.Longitude = Longitude;
        }

        public bool IsDataLoaded
        {
            get;
            private set;
        }
        public void LoadData()
        {
            #region backpacking
            var backpackingCategories = new List<ActivityCategory>()
            {
                //new ActivityCategory("Outdoors & Recreation", FoursquareConstants.OutdoorsAndRecreation),
                new ActivityCategory("Park", "4bf58dd8d48988d163941735"),
                new ActivityCategory("National Park", "52e81612bcbc57f1066b7a21"),
                new ActivityCategory("National Preserve", "52e81612bcbc57f1066b7a13"),
                new ActivityCategory("Mountain", "4eb1d4d54b900d56c88a45fc"),
                new ActivityCategory("Rock climbing sport", "50328a4b91d4c4b30a586d6b"),
                new ActivityCategory("Scenic lookout", "4bf58dd8d48988d165941735"),
                new ActivityCategory("Trail", "4bf58dd8d48988d159941735"),
            };
            var backpackingCategoryId = string.Empty;
            foreach (var item in backpackingCategories)
            {
                backpackingCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Backpacking", ActivityType.Summer, backpackingCategories, backpackingCategoryId);
            // this.Items.Add(new ActivityItemViewModel("Backpacking", ActivityType.Summer, backpackingCategories, backpackingCategoryId));

            #endregion

            #region Basketball
            var basketballCategories = new List<ActivityCategory>()
            {
                new ActivityCategory("Basketball Court", "4bf58dd8d48988d1e1941735"),
            };
            var basketballCategoryId = string.Empty;
            foreach (var item in basketballCategories)
            {
                basketballCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Basketball", ActivityType.Summer, basketballCategories, basketballCategoryId);
            //this.Items.Add(new ActivityItemViewModel("Basketball", ActivityType.Summer, basketballCategories, basketballCategoryId));
            #endregion

            #region Cycling
            var cyclingCategories = new List<ActivityCategory>()
            {
                new ActivityCategory("Park", "4bf58dd8d48988d163941735"),
                new ActivityCategory("Trail", "4bf58dd8d48988d159941735"),
            };
            var cyclingCategoryId = string.Empty;
            foreach (var item in cyclingCategories)
            {
                cyclingCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Cycling", ActivityType.Summer, cyclingCategories, cyclingCategoryId);
            //this.Items.Add(new ActivityItemViewModel("Cycling", ActivityType.Summer, cyclingCategories, cyclingCategoryId));
            #endregion

            #region Fishing
            var fishingCategories = new List<ActivityCategory>()
            {
                new ActivityCategory("Fishing Spot", "52e81612bcbc57f1066b7a0f"),
            };
            var fishingCategoryId = string.Empty;
            foreach (var item in fishingCategories)
            {
                fishingCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Fishing", ActivityType.Summer, fishingCategories, fishingCategoryId);
            //this.Items.Add(new ActivityItemViewModel("Fishing", ActivityType.Summer, fishingCategories, fishingCategoryId));
            #endregion

            #region Football
            var footballCategories = new List<ActivityCategory>()
            {
                new ActivityCategory("Soccer Field", "4cce455aebf7b749d5e191f5"),
            };
            var footballCategoryId = string.Empty;
            foreach (var item in footballCategories)
            {
                footballCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Football", ActivityType.Summer, footballCategories, footballCategoryId);
            //this.Items.Add(new ActivityItemViewModel("Football", ActivityType.Summer, footballCategories, footballCategoryId));
            #endregion

            #region Handball
            var handballCategories = new List<ActivityCategory>()
            {
                new ActivityCategory("Athletics & Sports", "4f4528bc4b90abdf24c9de85"),
                new ActivityCategory("Sports Club", "52e81612bcbc57f1066b7a2e"),
                new ActivityCategory("Recreation Center", "52e81612bcbc57f1066b7a26"),
            };
            var handballCategoryId = string.Empty;
            foreach (var item in handballCategories)
            {
                handballCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Handball", ActivityType.Summer, handballCategories, handballCategoryId);
            //this.Items.Add(new ActivityItemViewModel("Handball", ActivityType.Summer, handballCategories, handballCategoryId));
            #endregion

            #region Hiking
            var hikingCategories = new List<ActivityCategory>()
            {
                new ActivityCategory("Forest", "52e81612bcbc57f1066b7a23"),
                new ActivityCategory("Mountain", "4eb1d4d54b900d56c88a45fc"),
                new ActivityCategory("Trail", "4bf58dd8d48988d159941735"),
            };
            var hikingCategoryId = string.Empty;
            foreach (var item in hikingCategories)
            {
                hikingCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Hiking", ActivityType.Summer, hikingCategories, hikingCategoryId);
            //this.Items.Add(new ActivityItemViewModel("Hiking", ActivityType.Summer, hikingCategories, hikingCategoryId));
            #endregion

            #region Kayaking
            var kayakingCategories = new List<ActivityCategory>()
            {
                new ActivityCategory("River", "4eb1d4dd4b900d56c88a45fd"),
                new ActivityCategory("Lake", "4bf58dd8d48988d161941735"),
            };
            var kayakingCategoryId = string.Empty;
            foreach (var item in kayakingCategories)
            {
                kayakingCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Kayaking", ActivityType.Summer, kayakingCategories, kayakingCategoryId);
            //this.Items.Add(new ActivityItemViewModel("Kayaking", ActivityType.Summer, kayakingCategories, kayakingCategoryId));
            #endregion

            #region Paint Ball
            var paintBallCategories = new List<ActivityCategory>()
            {
                new ActivityCategory("Paintball Field", "5032829591d4c4b30a586d5e"),
            };
            var paintBallCategoryId = string.Empty;
            foreach (var item in paintBallCategories)
            {
                paintBallCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Paint Ball", ActivityType.Summer, paintBallCategories, paintBallCategoryId);
            //this.Items.Add(new ActivityItemViewModel("Paint Ball", ActivityType.Summer, paintBallCategories, paintBallCategoryId));
            #endregion

            #region Roller skating
            var rollerSkatingCategories = new List<ActivityCategory>()
            {
                new ActivityCategory("Athletics & Sports", "4f4528bc4b90abdf24c9de85"),
                new ActivityCategory("Park", "4bf58dd8d48988d163941735"),
            };
            var rollerSkatingCategoryId = string.Empty;
            foreach (var item in rollerSkatingCategories)
            {
                rollerSkatingCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Roller skating", ActivityType.Summer, rollerSkatingCategories, rollerSkatingCategoryId);
            //this.Items.Add(new ActivityItemViewModel("Roller skating", ActivityType.Summer, rollerSkatingCategories, rollerSkatingCategoryId));
            #endregion

            #region Running
            var runningCategories = new List<ActivityCategory>()
            {
                new ActivityCategory("Trail", "4bf58dd8d48988d159941735"),
                new ActivityCategory("Park", "4bf58dd8d48988d163941735"),
            };
            var runningCategoryId = string.Empty;
            foreach (var item in runningCategories)
            {
                runningCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Running", ActivityType.Summer, runningCategories, runningCategoryId);
            //this.Items.Add(new ActivityItemViewModel("Running", ActivityType.Summer, runningCategories, runningCategoryId));
            #endregion

            #region Skiing
            var skiingCategories = new List<ActivityCategory>()
            {
                new ActivityCategory("Ski Area", "4bf58dd8d48988d1e9941735"),
                new ActivityCategory("Ski Trail", "4eb1c0f63b7b52c0e1adc2eb"),
                new ActivityCategory("Ski Lodge", "4bf58dd8d48988d1eb941735"),
                new ActivityCategory("Ski Chalet", "4bf58dd8d48988d1ec941735"),
                new ActivityCategory("Ski Chairlift", "4eb1c0ed3b7b52c0e1adc2ea"),
            };
            var skiingCategoryId = string.Empty;
            foreach (var item in skiingCategories)
            {
                skiingCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Skiing", ActivityType.Winter, skiingCategories, skiingCategoryId);
            //this.Items.Add(new ActivityItemViewModel("Skiing", ActivityType.Winter, skiingCategories, skiingCategoryId));
            #endregion

            #region Swimming
            var swimmingCategories = new List<ActivityCategory>()
            {
                new ActivityCategory("Bathing Area", "52e81612bcbc57f1066b7a28"),
                new ActivityCategory("Beach", "4bf58dd8d48988d1e2941735"),
            };
            var swimmingCategoryId = string.Empty;
            foreach (var item in swimmingCategories)
            {
                swimmingCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Swimming", ActivityType.Winter, swimmingCategories, swimmingCategoryId);
            //this.Items.Add(new ActivityItemViewModel("Swimming", ActivityType.Winter, swimmingCategories, swimmingCategoryId));
            #endregion

            #region Urban exploration
            var urbanExplorationCategories = new List<ActivityCategory>()
            {
                new ActivityCategory("Fair", "4eb1daf44b900d56c88a4600"),
                new ActivityCategory("Botanical Garden", "52e81612bcbc57f1066b7a22"),
                new ActivityCategory("Castle", "50aaa49e4b90af0d42d5de11"),
                new ActivityCategory("Lighthouse", "4bf58dd8d48988d15d941735"),
                new ActivityCategory("Palace", "52e81612bcbc57f1066b7a14"),
                new ActivityCategory("Plaza", "4bf58dd8d48988d164941735"),
            };
            var urbanExplorationCategoryId = string.Empty;
            foreach (var item in urbanExplorationCategories)
            {
                urbanExplorationCategoryId += (item.CategoryId + ",");
            }
            ListOfVenuesForCategory("Urban exploration", ActivityType.Winter, urbanExplorationCategories, urbanExplorationCategoryId);
            //this.Items.Add(new ActivityItemViewModel("Urban exploration", ActivityType.Winter, urbanExplorationCategories, urbanExplorationCategoryId));
            #endregion
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private async void ListOfVenuesForCategory(string name, ActivityType type, List<ActivityCategory> categories, string CategoryId)
        {
            var foursquareVenues = new List<FoursquareVenue>();
            try
            {
                foursquareVenues = await FoursquareVenue.GetFoursquareVenues(Latitude, Longitude, CategoryId);

            }
            catch (Exception e)
            { }
            if (foursquareVenues.Count() > 0)
                this.Items.Add(new ActivityItemViewModel(name, type, categories, CategoryId, foursquareVenues.Count()));

        }
    }
}
